angular.module('webmac')
.controller('osCtrl',function($scope, $state){
	if (LS.get('booted') == undefined) {
        $state.go('boot');
    } else if(LS.get('logined') == undefined){
        $state.go('login');
    }else{
        $state.go('desktop');
    }
})

//启动
.controller('osBootCtrl',function($scope, $state, $timeout){
	$timeout(function(){
		$('#startSound')[0].play();
        var $spinner = $('#spinner');
        $spinner.removeClass('invisible');
        window.setTimeout(function() {
            $spinner.addClass('invisible');
            LS.set('booted', true);
            $state.go('login');
        }, 2000);
    },2000);
})

//登录页
.controller('osLoginCtrl',function($scope, $state, $timeout, $os, jconfig,$tooltip){
    var size = $os.size();
    $('#login > .row:eq(0)').height(size.height+'px');

    $scope.pwd = '';
    $scope.form_err = false;

    var $logo = $('#new-apple-logo');
    var $form = $('#login .form');
    $logo.animate({
        'margin-top': '-254px'
    }, 1000);
    window.setTimeout(function() {
        $form.removeClass('hidden');
    }, 1000);

    $scope.tooltip = function(e){
        var myTooltip = $tooltip(e, {title: 'My Title'});
    }
    $scope.dologin = function(pwd){
        if(pwd != jconfig.pwd){
            $scope.form_err = true;
        }else{
            LS.set('logined', true);
            $state.go('desktop');
        }
        return false;
    }
})

//桌面
.controller('osDesktopCtrl', function($scope, $os, $state){
    var size = $os.size();
    $('#desktop > .row:eq(0)').height(size.height+'px');
    $('#desktop > .row:eq(0)').css('overflow', 'hidden');
    $('#desktop').css('background-image', 'url(assets/img/Galaxy.jpg)');

    //登出
    $scope.logout = function(){
        LS.remove('logined');
        $state.go('login');
    }

    //关机
    $scope.shutdown = function(){
        LS.remove('booted');
        $scope.logout();
        $state.go('boot');
    }

    $scope.apps = [
        {
            title: '关于本系统',
            icon: 'finder.png',
            link: '#about',
            width: '545',
            height: '460'
            // win_title: ,
        },
        {
            title: '百度',
            icon: 'baidu.png',
            link: 'http://www.baidu.com',
            width: '740',
            height: '300',
            win_title: '百度'
        },
        {
            title: '豆瓣电台',
            icon: 'douban.png',
            link: 'http://douban.fm/partner/qq_plus',
            width: '545',
            height: '460',
            win_title: '豆瓣电台'
        },
        {
            title: 'ascii流程图',
            icon: 'ascii_flow.png',
            link: 'http://asciiflow.com',
            width: '1000',
            height: '700',
            win_title: 'ascii流程图'
        },
        {
            title: '五子棋',
            icon: 'gomoku.png',
            link: 'http://www.html5tricks.com/demo/wuziqi/game.html',
            width: '1000',
            height: '700',
            win_title: '五子棋'
        }

    ];

    $scope.openedApps = [];

})
;
